package dcc.component;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

public class DictionaryItemDeleteButtonEditor extends AbstractCellEditor
		implements TableCellEditor, ActionListener {

	private JButton button;
	private JDictionaryItemTable dictionaryItemTable;

	public DictionaryItemDeleteButtonEditor(
			JDictionaryItemTable dictionaryItemTable) {
		this.dictionaryItemTable = dictionaryItemTable;
		button = new JButton("\u5220\u9664");
		button.addActionListener(this);
	}

	@Override
	public Object getCellEditorValue() {
		return button.getActionCommand();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		fireEditingStopped();
		dictionaryItemTable.update(Integer.parseInt(button.getActionCommand()));
	}

	@Override
	public Component getTableCellEditorComponent(JTable table, Object value,
			boolean isSelected, int row, int column) {
		this.button.setActionCommand("" + value);
		return button;
	}

}
